import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/wroks/contract_bean.dart';
import 'package:app/src/ui/dialog/dailog.dart';
import 'package:app/src/ui/route/helper/route_helper.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';

import '../../../../../http/bean/works_2023/contractroyaltyrateapplycheck_bean.dart';
import '../../../../../http/bean/ywx_limit.dart';
import '../../../../../manager/audit_manager.dart';
import '../../../../../manager/ywx_manager.dart';
import '../../../../app_ui.dart';

///提成比例审核（更改设置）
class UiContractRoyaltyRateApplyCheckChange {
  ///跳转到更改记录
  static goContractRoyaltyRateApplyCheckChangeRecordRoute(
      BuildContext context, ContractRoyaltyRateApplyCheckBean? data) {
    //fixme 保存之前的AuditManager；防止发生后面的页面发生改变；
    var copyAuditManager = AuditManager.getAuditManager().copyAuditManager();
    AuditManager.getAuditManager().IsApproval = true;
    AppRouteHelper.goContractRoyaltyRateApplyCheckChangeRecordRoute(
            context, data?.ContractCode)
        ?.then((value) {
      //fixme 恢复之前的AuditManager
      AuditManager.setAuditManager(copyAuditManager);
    });
  }

  ///跳转到合同审核详情
  static goContractDetailsRoute(
      BuildContext context,
      ContractRoyaltyRateApplyCheckBean? data) {
    //fixme 保存之前的AuditManager；防止发生后面的页面发生改变；
    var copyAuditManager = AuditManager.getAuditManager().copyAuditManager();
    AuditManager.getAuditManager().item =
        YwxIdManager.getYwxItemWithContract(context);
    AuditManager.getAuditManager().item?.YwxName =
        "${AppStrings.of(context).hetongticbili}${data?.ContractCode}";
    AuditManager.getAuditManager().IsApproval = true;
    AuditManager.getAuditManager().ReviewTypeId = data?.ContractId;
    //print("合同编号ID:${data?.ContractId}");
    // AuditManager.getAuditManager().ApprovalState = ApprovalState;
    // AuditManager.getAuditManager().YwxId = YwxId;
    // AuditManager.getAuditManager().YwxName = YwxName;
    var ContractCode = data?.ContractCode ?? "";
    var ContractId = data?.ContractId ?? "";
    AppRouteHelper.goContractDetailsRoute2(
            context, ContractCode, ContractId, data,
            onlyBack: true)
        ?.then((value) {
      //fixme 恢复之前的AuditManager
      AuditManager.setAuditManager(copyAuditManager);
    });
  }

  ///合同编号
  static Widget build(
      BuildContext context, ContractRoyaltyRateApplyCheckBean? data,
      {String? title, int index = 0}) {
    List<Widget> children = [];
    //更改设置
    var button1 = AppUi.materialButton(AppStrings.of(context).ChangeSettings,
        onPressed: () {});
    children.add(button1);
    //合同基本信息
    var button2 = AppUi.outlineButton(
        AppStrings.of(context).Basiccontractinformation, onPressed: () {
      UiContractRoyaltyRateApplyCheckChange.goContractDetailsRoute(
          context, data);
    });
    children.add(button2);
    //更改记录
    var button3 =
        AppUi.outlineButton(AppStrings.of(context).Changerecord, onPressed: () {
      goContractRoyaltyRateApplyCheckChangeRecordRoute(context, data);
    });
    children.add(button3);
    var column = UiBase.row(context, children);
    var card = UiCard.build(
        context,
        SingleChildScrollView(
            child: column,
            scrollDirection: Axis.horizontal,
            physics: BouncingScrollPhysics()));
    return card;
  }
}
